package com.example.micro.netty.server.thread;

import java.util.concurrent.locks.LockSupport;

/**
 * static 对象 LuckSupport demo
 *
 * @author Code Farmer
 * @create 2020/10/20 5:50 下午
 */
public class StaticLockSupportDemo {

    static class StaticLockSupportThread extends Thread {

        @Override
        public void run() {
            System.out.println("in " + getName());
            LockSupport.park();
            if (Thread.interrupted()) {
                System.out.println(getName() + "已经被中断");
            }
            System.out.println(getName() + "执行结束");
        }

    }

    public static void main(String[] args) {

//        LockSupportThread t1 = new LockSupportThread();
//        LockSupportThread t2 = new LockSupportThread();

        StaticLockSupportThread t1 = new StaticLockSupportThread();
        StaticLockSupportThread t2 = new StaticLockSupportThread();

        t1.start();
        try {
            Thread.sleep(0);
            t2.start();
            t1.interrupt();
            LockSupport.unpark(t2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }
}
